package edu.lyun.stumvc.controller;

import edu.lyun.stumvc.entity.Student;
import edu.lyun.stumvc.entity.vo.request.StudentRequest;
import edu.lyun.stumvc.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class StudentController {
    @Resource
    StudentService studentService;

    @GetMapping(value = "/index", produces = "application/json;charset=UTF-8")
    public String index() {
        return "index";
    }

    @ResponseBody
    @GetMapping(value = "/select-all-from-students", produces = "application/json;charset=UTF-8")
    public List<StudentRequest> selectAllFromStudents() {
        return studentService.selectAllFromStudents();
    }

    @ResponseBody
    @GetMapping(value = "/delete-students-where-id-equal", produces = "application/json;charset=UTF-8")
    public int deleteStudentsWhereIdEqual(@RequestParam("id") int id) {
        return studentService.deleteStudentsWhereIdEqual(id);
    }

    @ResponseBody
    @PostMapping(value = "/update-students-by-student", produces = "application/json;charset=UTF-8")
    public int updateStudentsByStudent(@RequestBody Student student) {
        return studentService.updateStudentsByStudent(student);
    }

    @ResponseBody
    @PostMapping(value = "/insert-into-students-by-student", produces = "application/json;charset=UTF-8")
    public int insertIntoStudentsByStudent(@RequestBody Student student) {
        return studentService.insertIntoStudentsByStudent(student);
    }

}
